class MainController < ApplicationController
  def index
    session[:djinn] ||= {}
    @djinns = Djinn.find(:all).sort_by{ |i| i[:name] }.sort_by{|x| x[:element]}
    @chars=Character.find(:all)
    @gsclasses=Gsclass.find(:all)
    
  end
  
  def add_djinn
    if session[:djinn].length<=6
      djinn_id = params[:id].split("_")[1]
      @djinn=Djinn.find(djinn_id)
      session[:djinn][djinn_id] = @djinn.name,"_", @djinn.element
      
    else
      flash[:notice] = 'Can\'t insert anymore Djinn.'
    
  end
  update_stats
  end
  
  def remove_djinn
    djinn_id = params[:id].split("_")[1]
    session[:djinn].delete(djinn_id)
    update_stats
  end
  
  def update_stats
    render :partial => 'djinn_move'
  end
end
